package com.dianping.cat.home.heavy.transform;
import com.dianping.cat.home.heavy.IVisitor;
import com.dianping.cat.home.heavy.entity.HeavyCache;
import com.dianping.cat.home.heavy.entity.HeavyCall;
import com.dianping.cat.home.heavy.entity.HeavyReport;
import com.dianping.cat.home.heavy.entity.HeavySql;
import com.dianping.cat.home.heavy.entity.Service;
import com.dianping.cat.home.heavy.entity.Url;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

public class DefaultNativeParser implements IVisitor {
  private DefaultLinker m_linker;
  
  public DefaultNativeParser(InputStream in) {
/*  18 */     this.m_linker = new DefaultLinker(true);




/*  23 */     this.m_in = new DataInputStream(in);
  }
  private DataInputStream m_in;
  
/*  27 */   public static HeavyReport parse(byte[] data) { return parse(new ByteArrayInputStream(data)); }

  
  public static HeavyReport parse(InputStream in) {
    DefaultNativeParser parser = new DefaultNativeParser(in);
    HeavyReport heavyReport = new HeavyReport();
    
    try {
/*  35 */       heavyReport.accept(parser);
    } catch (RuntimeException e) {
/*  37 */       if (e.getCause() == null || !(e.getCause() instanceof java.io.EOFException))
      {
      
/*  40 */         throw e;
      }
    }
    
/*  44 */     parser.m_linker.finish();
/*  45 */     return heavyReport;
  }


  
  public void visitHeavyCache(HeavyCache heavyCache) {
    byte tag;
/*  52 */     while ((tag = readTag()) != -1) {
/*  53 */       visitHeavyCacheChildren(heavyCache, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }
  
  protected void visitHeavyCacheChildren(HeavyCache heavyCache, int _field, int _type) {
/*  58 */     switch (_field) {
      case 33:
/*  60 */         if (_type == 1) {
/*  61 */           Url url = new Url();

/*  63 */           visitUrl(url);
/*  64 */           this.m_linker.onUrl(heavyCache, url); break;
/*  65 */         }  if (_type == 2) {
/*  66 */           for (int i = readInt(); i > 0; i--) {
/*  67 */             Url url = new Url();

/*  69 */             visitUrl(url);
/*  70 */             this.m_linker.onUrl(heavyCache, url);
          }
        }
        break;
      case 34:
/*  75 */         if (_type == 1) {
/*  76 */           Service service = new Service();

          visitService(service);
/*  79 */           this.m_linker.onService(heavyCache, service); break;
/*  80 */         }  if (_type == 2) {
/*  81 */           for (int i = readInt(); i > 0; i--) {
/*  82 */             Service service = new Service();

/*  84 */             visitService(service);
/*  85 */             this.m_linker.onService(heavyCache, service);
          }
        }
        break;
    }
  }


  
  public void visitHeavyCall(HeavyCall heavyCall) {
    byte tag;
/*  96 */     while ((tag = readTag()) != -1) {
/*  97 */       visitHeavyCallChildren(heavyCall, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }
  
  protected void visitHeavyCallChildren(HeavyCall heavyCall, int _field, int _type) {
/* 102 */     switch (_field) {
      case 33:
/* 104 */         if (_type == 1) {
/* 105 */           Url url = new Url();

/* 107 */           visitUrl(url);
/* 108 */           this.m_linker.onUrl(heavyCall, url); break;
/* 109 */         }  if (_type == 2) {
/* 110 */           for (int i = readInt(); i > 0; i--) {
/* 111 */             Url url = new Url();

/* 113 */             visitUrl(url);
/* 114 */             this.m_linker.onUrl(heavyCall, url);
          }
        }
        break;
      case 34:
/* 119 */         if (_type == 1) {
/* 120 */           Service service = new Service();

/* 122 */           visitService(service);
/* 123 */           this.m_linker.onService(heavyCall, service); break;
/* 124 */         }  if (_type == 2) {
/* 125 */           for (int i = readInt(); i > 0; i--) {
/* 126 */             Service service = new Service();

/* 128 */             visitService(service);
/* 129 */             this.m_linker.onService(heavyCall, service);
          }
        }
        break;
    }
  }


  
  public void visitHeavyReport(HeavyReport heavyReport) {
    byte tag;
/* 140 */     if ((tag = readTag()) != -4) {
/* 141 */       throw new RuntimeException(String.format("Malformed payload, expected: %s, but was: %s!", new Object[] { Integer.valueOf(-4), Byte.valueOf(tag) }));
    }
    
/* 144 */     while ((tag = readTag()) != -1)
/* 145 */       visitHeavyReportChildren(heavyReport, (tag & 0xFF) >> 2, tag & 0x3); 
  } protected void visitHeavyReportChildren(HeavyReport heavyReport, int _field, int _type) {
    HeavyCache heavyCache;
    HeavyCall heavyCall;
    HeavySql heavySql;
/* 150 */     switch (_field) {
      case 1:
/* 152 */         heavyReport.setDomain(readString());
        break;
      case 2:
/* 155 */         heavyReport.setStartTime(readDate());
        break;
      case 3:
/* 158 */         heavyReport.setEndTime(readDate());
        break;
      case 33:
/* 161 */         heavySql = new HeavySql();

/* 163 */         visitHeavySql(heavySql);
/* 164 */         this.m_linker.onHeavySql(heavyReport, heavySql);
        break;
      case 34:
/* 167 */         heavyCall = new HeavyCall();

/* 169 */         visitHeavyCall(heavyCall);
/* 170 */         this.m_linker.onHeavyCall(heavyReport, heavyCall);
        break;
      case 35:
/* 173 */         heavyCache = new HeavyCache();

/* 175 */         visitHeavyCache(heavyCache);
/* 176 */         this.m_linker.onHeavyCache(heavyReport, heavyCache);
        break;
    }
  }


  
  public void visitHeavySql(HeavySql heavySql) {
    byte tag;
/* 185 */     while ((tag = readTag()) != -1) {
/* 186 */       visitHeavySqlChildren(heavySql, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }
  
  protected void visitHeavySqlChildren(HeavySql heavySql, int _field, int _type) {
/* 191 */     switch (_field) {
      case 33:
/* 193 */         if (_type == 1) {
/* 194 */           Url url = new Url();

/* 196 */           visitUrl(url);
/* 197 */           this.m_linker.onUrl(heavySql, url); break;
/* 198 */         }  if (_type == 2) {
/* 199 */           for (int i = readInt(); i > 0; i--) {
/* 200 */             Url url = new Url();

/* 202 */             visitUrl(url);
/* 203 */             this.m_linker.onUrl(heavySql, url);
          }
        }
        break;
      case 34:
/* 208 */         if (_type == 1) {
/* 209 */           Service service = new Service();

/* 211 */           visitService(service);
/* 212 */           this.m_linker.onService(heavySql, service); break;
/* 213 */         }  if (_type == 2) {
/* 214 */           for (int i = readInt(); i > 0; i--) {
/* 215 */             Service service = new Service();

/* 217 */             visitService(service);
/* 218 */             this.m_linker.onService(heavySql, service);
          }
        }
        break;
    }
  }


  
  public void visitService(Service service) {
    byte tag;
/* 229 */     while ((tag = readTag()) != -1) {
/* 230 */       visitServiceChildren(service, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }
  
  protected void visitServiceChildren(Service service, int _field, int _type) {
/* 235 */     switch (_field) {
      case 1:
/* 237 */         service.setDomain(readString());
        break;
      case 2:
/* 240 */         service.setName(readString());
        break;
      case 3:
/* 243 */         service.setLogview(readString());
        break;
      case 4:
/* 246 */         service.setCount(readLong());
        break;
      case 5:
/* 249 */         service.setKey(readString());
        break;
    }
  }


  
  public void visitUrl(Url url) {
    byte tag;
/* 258 */     while ((tag = readTag()) != -1) {
/* 259 */       visitUrlChildren(url, (tag & 0xFF) >> 2, tag & 0x3);
    }
  }
  
  protected void visitUrlChildren(Url url, int _field, int _type) {
/* 264 */     switch (_field) {
      case 1:
/* 266 */         url.setDomain(readString());
        break;
      case 2:
/* 269 */         url.setName(readString());
        break;
      case 3:
/* 272 */         url.setLogview(readString());
        break;
      case 4:
/* 275 */         url.setCount(readLong());
        break;
      case 5:
/* 278 */         url.setKey(readString());
        break;
    }
  }
  
  private Date readDate() {
    try {
/* 285 */       return new Date(readVarint(64));
/* 286 */     } catch (IOException e) {
/* 287 */       throw new RuntimeException(e);
    }
  }
  
  private int readInt() {
    try {
/* 293 */       return (int)readVarint(32);
/* 294 */     } catch (IOException e) {
/* 295 */       throw new RuntimeException(e);
    }
  }
  
  private long readLong() {
    try {
/* 301 */       return readVarint(64);
/* 302 */     } catch (IOException e) {
/* 303 */       throw new RuntimeException(e);
    }
  }
  
  private String readString() {
    try {
/* 309 */       return this.m_in.readUTF();
/* 310 */     } catch (IOException e) {
/* 311 */       throw new RuntimeException(e);
    }
  }
  
  private byte readTag() {
    try {
/* 317 */       return this.m_in.readByte();
/* 318 */     } catch (IOException e) {
/* 319 */       throw new RuntimeException(e);
    }
  }
  
  protected long readVarint(int length) throws IOException {
/* 324 */     int shift = 0;
/* 325 */     long result = 0L;

/* 327 */     while (shift < length) {
/* 328 */       byte b = this.m_in.readByte();
/* 329 */       result |= (b & 0x7F) << shift;
/* 330 */       if ((b & 0x80) == 0) {
/* 331 */         return result;
      }
/* 333 */       shift += 7;
    }
    
/* 336 */     throw new RuntimeException("Malformed variable int " + length + "!");
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/heavy/transform/DefaultNativeParser.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */